import useSWR from 'swr'

interface Item {
  id: number
  name: string
}

export const useGetList = () => {
  const { data, error, isLoading, mutate } = useSWR<Item[]>(
    'http://localhost:3000/swr',
    (url: string) => fetch(url).then((res) => res.json()),
  )
  return { data, error, isLoading, mutate }
}

export const useDeleteItem = () => {
  const deleteItem = async (id: number) => {
    return fetch(`http://localhost:3000/swr/delete/${id}`, {
      method: 'POST',
    })
  }
  return { deleteItem }
}
